﻿package mortal.game.view.rebate.item
{
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.events.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;

    public class RebateTabsPanel extends GSprite
    {
        protected var _tabList:CellsGridSprite;
        protected var _selectBoard:ScaleBitmap;
        public var selWid:int = 164;
        public var selHei:int = 64;
        private var _cellWid:int = 100;
        private var _cellHei:int = 60;
        private var _dir:String = "v";
        public var bePos:int = -3;
        public var cellB:Class;
        private var _numToTab:Object;

        public function RebateTabsPanel()
        {
            this._numToTab = {};
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            if (this.cellB == null)
            {
                this.cellB = RebateTabBaseCell;
            }
            this._tabList = UIFactory.getUICompoment(CellsGridSprite);
            this._tabList.colNum = 1;
            this._tabList.vCellWid = this._cellWid;
            this._tabList.hCellWid = this._cellHei;
            this._tabList.genCellFun = UIFactory.getUICompoment;
            this._tabList.genCells(1, this.cellB);
            this._tabList.x = 0;
            this._tabList.y = 0;
            this.addChild(this._tabList);
            this._selectBoard = UIFactory.bg(-3, -3, 164, 64, this, ImagesConst.selectFilter);
            this._tabList.configEventListener(MouseEvent.CLICK, this.onSelectHd);
            this._selectBoard.visible = false;
            return;
        }// end function

        public function setAttr(param1:int = 100, param2:int = 60, param3:int = 164, param4:int = 64, param5:int = -3, param6:String = "v") : void
        {
            this._dir = param6;
            this._cellWid = param1;
            this._cellHei = param2;
            if (this._dir == "v")
            {
                this._tabList.colNum = 1;
            }
            else
            {
                this._tabList.colNum = 100;
            }
            this._tabList.vCellWid = this._cellWid;
            this._tabList.hCellWid = this._cellHei;
            this._selectBoard.width = param3;
            this._selectBoard.height = param4;
            this.bePos = param5;
            return;
        }// end function

        public function setData(param1:Array) : void
        {
            var _loc_3:* = undefined;
            var _loc_4:RebateTabBaseCell = null;
            if (param1 == null)
            {
                return;
            }
            this._numToTab = {};
            this._tabList.genCells(param1.length, this.cellB);
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = param1[_loc_2];
                _loc_4 = this._tabList.cellArr[_loc_2] as RebateTabBaseCell;
                if (_loc_4)
                {
                    _loc_4.setData(_loc_3);
                    this._numToTab[_loc_3] = _loc_4;
                }
                _loc_2++;
            }
            return;
        }// end function

        public function setHasRewardEffect(param1:int, param2:Boolean) : void
        {
            var _loc_3:* = this._numToTab[param1] as RebateTabSCellSp;
            if (_loc_3)
            {
                _loc_3.setRewardFlag(param2);
            }
            return;
        }// end function

        public function onSelectHd(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as RebateTabBaseCell;
            if (_loc_2 == null || this._tabList == null)
            {
                return;
            }
            var _loc_3:* = this._tabList.cellArr.indexOf(_loc_2);
            if (_loc_3 != -1)
            {
                this.setSelectEff(_loc_3);
            }
            return;
        }// end function

        public function setSelectEff(param1:int) : void
        {
            if (param1 < 0)
            {
                return;
            }
            this._selectBoard.visible = true;
            if (this._dir == "v" && this._selectBoard)
            {
                this._selectBoard.y = this.bePos + param1 * this._cellHei;
            }
            else
            {
                this._selectBoard.x = this.bePos + param1 * this._cellWid;
            }
            this.dispatchEvent(new DataEvent(EventName.RebateTabSelect, param1));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._tabList.dispose(param1);
            this._selectBoard.dispose(param1);
            this._tabList = null;
            this._selectBoard = null;
            this.selWid = 164;
            this.selHei = 64;
            this._cellWid = 100;
            this._cellHei = 60;
            this._dir = "v";
            this.bePos = -3;
            return;
        }// end function

    }
}
